define(["coAjax", "jSouper", "lrz"], function(coAjax, jSouper) {
    function _upload_imgs(resultfile, callback) {
        // console.log("file,", resultfile);
        var formData = new FormData();
        formData.append("upload", resultfile);
        $.ajax({
            url: "http://apibbs.shengyi8888.com/file/upload",
            method: "POST",
            dataType: "json",
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
        }).then(function(result) {
            img_url = result.server_url + result.key;
            // 运行回调
            callback(img_url);
        });
        // coAjax.post("http://apibbs.shengyi8888.com/file/upload", formData, function(img_info) {
        //     console.log(img_info)
        //     var img_url = "http://7xpxgs.com1.z0.glb.clouddn.com/" + img_info.key;
        //     //运行回调
        //     callback(null, 1, img_url);
        // }).on("uploadProgress", function(event, position, total, percentComplete) {
        //     callback(null, percentComplete, null);
        // });
    };

    var lrz_config = {
        width: 1280,
        quality: 1
    };

    return function(file, options, callback) {
        if (arguments.length < 3) {
            callback = options;
            options = null;
        }
        //图片处理进度事件
        (callback instanceof Function) || (callback = jSouper.$.noop);

        _upload_imgs(file, callback);
        // callback(null, 0, null);
        // lrz(file, options || lrz_config, function(result) {
        //     console.log(result)
        //         //处理完成，上传
        //     _upload_imgs(result, callback);
        // });

    }
});